import 'package:flutter/material.dart';

import 'loading_dialog.dart';

class LoadingController {
  static late BuildContext? _popContext;

  static LoadingController? _instance;

  LoadingController._();

  static LoadingController getInstance() {
    return _instance ??= LoadingController._();
  }

  static void show(BuildContext context, String text) {
    showGeneralDialog(
      context: context,
      pageBuilder: (ctx, ani, ani2) {
        _popContext = ctx;
        return LoadingDialog(text);
      },
      barrierColor: Colors.black.withOpacity(0.01),
      barrierLabel: '',
      barrierDismissible: false,
    );
  }

  static void complete() {
    if (Navigator.canPop(_popContext!)) {
      Navigator.pop(_popContext!);
    }
  }
}
